/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.cms.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.fyx.mula.entity.MulaLanguage;
import org.fyx.secure.entity.SecureUser;

/**
 *
 * @author ydenek
 */
@Entity
@Table(name = "cms_article")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CmsArticle.findAll", query = "SELECT c FROM CmsArticle c"),
    @NamedQuery(name = "CmsArticle.findById", query = "SELECT c FROM CmsArticle c WHERE c.id = :id"),
    @NamedQuery(name = "CmsArticle.findByTitle", query = "SELECT c FROM CmsArticle c WHERE c.title = :title"),
    @NamedQuery(name = "CmsArticle.findByTimeCreate", query = "SELECT c FROM CmsArticle c WHERE c.timeCreate = :timeCreate"),
    @NamedQuery(name = "CmsArticle.findByTimeEditation", query = "SELECT c FROM CmsArticle c WHERE c.timeEditation = :timeEditation")})
public class CmsArticle implements Serializable {

    private static final long serialVersionUID = 1L;
    @TableGenerator(name = "CMS_ARTICLE_GEN",
        table = "SEQUENCE",
        pkColumnName = "SEQ_NAME",
        valueColumnName = "SEQ_COUNT",
        pkColumnValue = "CMS_ARTICLE")
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator="CMS_ARTICLE_GEN")
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 255)
    @Column(name = "title")
    private String title;
    @Lob
    @Size(max = 2147483647)
    @Column(name = "content")
    private String content;
    @Column(name = "time_create")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeCreate;
    @Column(name = "time_editation")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeEditation;
    @JoinColumn(name = "author", referencedColumnName = "id_user")
    @ManyToOne
    private SecureUser author;
    @JoinColumn(name = "language", referencedColumnName = "iso_language")
    @ManyToOne(optional = false)
    private MulaLanguage language;

    public CmsArticle() {
    }

    public CmsArticle(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getTimeCreate() {
        return timeCreate;
    }

    public void setTimeCreate(Date timeCreate) {
        this.timeCreate = timeCreate;
    }

    public Date getTimeEditation() {
        return timeEditation;
    }

    public void setTimeEditation(Date timeEditation) {
        this.timeEditation = timeEditation;
    }

    public SecureUser getAuthor() {
        return author;
    }

    public void setAuthor(SecureUser author) {
        this.author = author;
    }

    public MulaLanguage getLanguage() {
        return language;
    }

    public void setLanguage(MulaLanguage language) {
        this.language = language;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CmsArticle)) {
            return false;
        }
        CmsArticle other = (CmsArticle) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fyx.cms.entity.CmsArticle[ id=" + id + " ]";
    }
}
